﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using xiushen.Domain;
using xiushen.Infrastructure;
using xiushen.Models;

namespace xiushen.Controllers
{
    public class XiuShenController : Controller
    {
        //
        // GET: /XiuShen/

        private IBookService service; 
        public XiuShenController()
        {
            service = new BookRepository();
        }
        public XiuShenController(IBookService service)
        {
            this.service = service;
        }
        public ActionResult Category()
        {
            var model = new BookViewModel();
            model.RootCategories = service.GetRootCategorys();
            model.AllCategorys = service.GetCategoriesByType(Constants.Book);
            return View(model);
        }
        public ActionResult Books(int id,int? pageIndex)
        {
            var model = new BookViewModel();
            model.Category = service.GetByID(id);
            model.TotalBook = model.Category.Book.Count;
            model.PageIndex = pageIndex ?? 1;
            model.RootCategories = service.GetRootCategorys();
            model.AllCategorys = service.GetCategoriesByType(Constants.Book);
            return View(model);
        }

        public ActionResult MoreBooks(int categoryId,int?pageIndex)
        {
            var model = service.GetByID(categoryId);
            return View(model);
        }

        public ActionResult MoreVideos(int categoryId, int? pageIndex)
        {
            var model = service.GetByID(categoryId);
            return View(model);
        }
        public  ActionResult Chapters(int categoryId,int bookId)
        {
            var model = service.GetByID(categoryId,bookId);
            return View(model);
        }

        public ActionResult Content(int categoryId,int bookId,int chapterId)
        {
            var model = service.GetChapterContent(bookId, chapterId,categoryId);
            return View(model); 
        }

        public ActionResult BookContent(int categoryId,int bookId)
        {
            var model = service.GetByID(categoryId, bookId);
            return View(model);
        }

        public ActionResult Index()
        {
            var model = service.GetAllCategorys();  
            return View(model);
        }
        public ActionResult PdfView(string url)
        {
            ViewBag.Url = url;
            return View();
        }

        public ActionResult PdfBooks(int categoryId)
        {
            var model = service.GetAttachments(categoryId,Constants.Book);
            return View(model);
        }

        public ActionResult PdfLists()
        {
            var model = service.GetCategoriesByType(Constants.Book);
            return View(model);
        }

        public ActionResult BookLists()
        {
            var model = service.GetCategoriesByType(Constants.Book);
            return View(model);
        }

        public ActionResult BrowserPics()
        {
            var model = service.GetCategoriesByType(Constants.Image);
            return View(model);
        }

        public ActionResult BrowserPdfs()
        {
            return View();
        }
        public ActionResult VideosList()
        {
            var model = service.GetCategoriesByType(Constants.Video);
            return View(model);
        }
        public ActionResult ViewVideos(int categoryId,int id)
        {
            var model = service.GetVideosByID(categoryId, id);
            return View(model);
        }

        public ActionResult ViewPic(int categoryId)
        {
            var datas = service.GetAttachments(categoryId, Constants.Image);
            return View(datas);
        }

        public ActionResult SearchBooks(string name)
        {
            var datas = service.SearchBooks(name);
            var pdfBooks = service.SearchAttachment(name);
            var mode = new BookQueryResult() {Books = datas,PdfBooks = pdfBooks};
            return View(mode);
        }
        public ActionResult SearchVideos(string name)
        {
            var datas = service.SearchVieos(name);
            return View(datas);
        }
        public ActionResult Loading()
        {
            return View();
        }
       
    }
}
